<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改新闻')" />
    <th:block th:include="include :: tinymce"/>
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-content-edit" th:object="${cmsContent}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <textarea name="title" class="form-control" placeholder="新闻标题">[[*{title}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">概要：</label>
                <div class="col-sm-8">
                    <textarea name="brief" class="form-control" placeholder="内容的概要">[[*{brief}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <textarea class="summernote" id="content" name="content" th:field="*{content}"></textarea>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="idx" th:field="*{idx}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">热门标识：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="radio" checked="" value="0"  name="hotFlag" th:field="*{hotFlag}"/>
                        <label>否</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio"  value="1"  name="hotFlag" th:field="*{hotFlag}" />
                        <label>是</label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">链接地址：</label>
                <div class="col-sm-8">
                    <input name="ext1" class="form-control" type="text" th:field="*{ext1}" autocomplete="off" placeholder="链接地址">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">打开方式：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="radio" checked="" value="_self"  name="ext2" th:field="*{ext2}"/>
                        <label>当前页</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" checked="" value="_target"  name="ext2"  th:field="*{ext2}"/>
                        <label>新窗口</label>
                    </div>
                </div>
            </div>
            <div class="form-group" >
                <input name="thumb" id="thumb" th:field="*{thumb}" class="form-control" type="hidden">
                <label class="col-sm-3 control-label ">图片</label>
                <div class="col-sm-8">
                    <input id="singleFile" name="file" type="file">
                </div>
            </div>

            <div class="box-footer">
                <div class="col-sm-offset-5 col-sm-6">
                    <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                    <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "news/content";
        var imgUrl =  [[${cmsContent.thumb}]]
        var initialPreview = []

        if(imgUrl) {
            initialPreview = [base+imgUrl]
        }

        $("#form-content-edit").validate({
            rules: {
                title: "required"
            },
            messages: {
                title:  "必填项"
            }
        });

        $("#singleFile").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true,
            initialPreviewAsData: true,
            initialPreview: initialPreview
        }).on('fileuploaded', function (event, data, previewId, index) {
            var rsp = data.response;
            log.info("return url：" + rsp.url)
            log.info("reutrn fileName：" + rsp.fileName)
            log.info("reutrn newFileName：" + rsp.newFileName)
            log.info("return originalFilename：" + rsp.originalFilename)

            $('#thumb').val(rsp.fileName)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        }).on('filedeleted', function() {
            $('#thumb').val('')
        }).on('filesuccessremove', function() {
            $('#thumb').val('')
        }).on('filecleared', function() {
            $('#thumb').val('')
        })

        function submitHandler() {
            $('#content').val(tinyMCE.get('content').getContent())
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/edit", $('#form-content-edit').serialize());
            }
        }

        $(function() {
            initTinyMec('#content')
        });
    </script>
</body>
</html>